(*
  Copyright (c) 2009 Barry Schwartz

  Permission is hereby granted, free of charge, to any person
  obtaining a copy of this software and associated documentation
  files (the "Software"), to deal in the Software without
  restriction, including without limitation the rights to use,
  copy, modify, merge, publish, distribute, sublicense, and/or sell
  copies of the Software, and to permit persons to whom the
  Software is furnished to do so, subject to the following
  conditions:

  The above copyright notice and this permission notice shall be
  included in all copies or substantial portions of the Software.

  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
  OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
  HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
  WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  OTHER DEALINGS IN THE SOFTWARE.
*)

open XNum
open SymbolTable
open UTypes
  
exception Syntax_error of Location.location * uc_string
exception Runtime_error of uc_string
  
val runtime_error : string -> 'a
  
(*
type compare = [ Equal | Less | LessEqual | Greater | GreaterEqual | Inequal ];

type relation = unit; (* FIX *)
*)
type unknown =
    partial_value ref

and partial_value =
  | Unbound
  | Constraint of unknown list
  | Bool of bool
  | Number of num
  | Char of uc_char
  | Symbol of symbol
  | LinForm of unknown LinForm.lin_form
  | Primitive1 of (unknown -> partial_value)
  | Primitive2 of (unknown -> unknown -> partial_value)
  | PrimitiveN of int * (unknown list -> partial_value)
  | Function of environment * int * bytecode array
  | Chain of environment * bytecode array
  | Relation of int * bytecode array (* aritiy, local variables, and equations *)
  | Application of partial_value * int * unknown list
  | Nil
  | List of unknown * unknown
  | Tuple of unknown array
  | Dictionary of unknown SymbolMap.t
  | Opaque of unknown Opaque.opaque

and bytecode =
  | BDup
  | BPop
  | BPopN of int
  | BConst of partial_value
  | BGlobal of unknown
  | BVariable of int * int
  | BFunction of int * bytecode array
  | BDictionary of symbol array
  | BPair
  | BTuple of int
  | BSet of int * int
  | BApply of int
  | BReturn
  | BCondJump of int
  | BJump of int
  | BLocal of int
  | BEndLocal
  | BMatch1 of pattern_check list * int * int * int
  | BMatchN of (pattern_check list) array * int * int * int
  | BUnify
  | BRaise of string

and pattern_check =
  | PCAnything
  | PCVariable of int
  | PCNumber of num
  | PCChar of uc_char
  | PCSymbol of symbol
  | PCTuple of int
  | PCNil
  | PCConsList
  | PCAssign of int

and environment =
    (unknown array) list

val identical : unknown -> unknown -> bool
val compare_unknowns : unknown -> unknown -> LinForm.compare_result
val create_unbound : 'a -> unknown
val create_unknown : partial_value -> unknown
val add_constraint : unknown -> unknown list -> unknown list
val merge_constraints : unknown list -> unknown list -> unknown list
val type_name : partial_value -> string
